package com.hotelManagerSystem.mapper;

import com.hotelManagerSystem.model.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lqx
 * @since 2021-12-22
 */


public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where `username` = #{username}")
    User queryByUsername(String username);

    @Insert("insert `user`  (username, `password`, salt, nikename, name, sex, tel, id_card, head_img, user_state)" +
            "VALUES (#{username}, #{password}, #{salt}, #{nikename}, #{name}, #{sex}, #{tel}, #{idCard}, #{headImg}, " +
            "#{userState})")
    Integer addUser(User user);

    @Delete("delete from `user` where uid = #{id}")
    int delUser(Integer id);

    @Update("update `user` set username=#{username}, `password` = #{password}," +
            "nikename = #{nikename}, name = #{name}, sex = #{sex}, tel = #{tel}, " +
            "id_card = #{idCard}, user_state = #{userState} where uid = #{uid}")
    int updateUser(User user);

    @Select("select * from `user` where `name` like #{name} or `username` like #{name}")
    List<User> queryByName(String name);
    @Select("select * from `user`")
    List<User> queryAll();

    ///////////
/*    //一.查询所有
    @Select("select * from `user`")
    List<User>  queryUserList();*/
    //二:黑名单功能---根据用户的id把该用户添加进黑名单
    @Update("update `user` set user_state=0 where uid=#{uid}")
    int addUserById(Integer uid);
    //三:黑名单功能:根据用户的id把该该用户从黑名单中移除(即黑名单的删除)
    @Update("update `user` set user_state=1 where uid=#{uid}" )
    int deleteUserById(Integer uid);
    //四:查询所有黑名单用户
    @Select("select * from `user` where user_state=0")
    List<User> selectBlackUserList();
    //五:查询所有白名单用户
    @Select("select * from `user` where user_state=1")
    List<User> selectWhiteUserList();
    //六:根据用户名查询用户列表(模糊查询)
    @Select("select * from `user` where username like concat('%',#{username},'%')")
    List<User> selectUserByUsername(String username);

    @Insert("insert into user values(null,#{username},#{password},#{salt},null,null,null,null,null,null,1)")
    int registerUser(@Param("username")String username, @Param("password")String newPassword, @Param("salt")String salt);
}
